package com.sunlong.jiangwei.web;


import com.sunlong.jiangwei.entity.JwCategory;
import com.sunlong.jiangwei.entity.result.Result;
import com.sunlong.jiangwei.service.IJwCategoryService;
import com.sunlong.jiangwei.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孙龙
 * @since 2021-02-19
 */
@RestController
@RequestMapping("/jiangwei/jw-category")
public class JwCategoryController {
    @Autowired
    private IJwCategoryService categoryService;

    @GetMapping("/findAll")
    public Result<List<JwCategory>> findAll(){
        return ResultUtil.data(categoryService.findAll());
    }

    @DeleteMapping("/deleteById")
    public Result<Void> deleteById(long id){
        categoryService.deleteById(id);
        return ResultUtil.success("success");
    }

    @PostMapping("/saveCategory")
    public Result<Void> saveCategory(@RequestBody JwCategory category){
        categoryService.saveOrUpdateCategory(category);
        return ResultUtil.success("success");
    }
}
